package com.peas.platform.module.icims.budget.project.api;

import cn.hutool.core.bean.BeanUtil;
import com.peas.platform.common.core.dto.ResponseDto;
import com.peas.platform.module.icims.budget.project.api.req.BudgetProjectNoticeReq;
import com.peas.platform.module.icims.budget.project.dto.BudgetProjectNoticeDto;
import com.peas.platform.module.icims.budget.project.dto.BudgetProjectNoticeFileDto;
import com.peas.platform.module.icims.budget.project.service.BudgetProjectNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "自定义接口-[预算控制]编制通知")
@RestController
@RequestMapping("/api/v1/customBudgetProjectNotice")
public class CustomBudgetProjectNoticeController {

    @Resource
    private BudgetProjectNoticeService budgetProjectNoticeService;

    @ApiOperation(value = "添加编制通知")
    @PostMapping("/saveBudgetProjectNotice")
    public ResponseDto<Integer> saveBudgetProjectNotice(@RequestBody @Valid BudgetProjectNoticeReq req) {
        BudgetProjectNoticeDto dto = BeanUtil.copyProperties(req, BudgetProjectNoticeDto.class);
        List<BudgetProjectNoticeFileDto> files = BeanUtil.copyToList(req.getFiles(), BudgetProjectNoticeFileDto.class);
        int result = budgetProjectNoticeService.saveBudgetProjectNotice(dto, files);
        return ResponseDto.getSuccessResponseDto(result);
    }

    @ApiOperation(value = "修改编制通知")
    @PostMapping("/modifyBudgetProjectNotice")
    public ResponseDto<Integer> modifyBudgetProjectNotice(@RequestBody @Valid BudgetProjectNoticeReq req) {
        BudgetProjectNoticeDto dto = BeanUtil.copyProperties(req, BudgetProjectNoticeDto.class);
        List<BudgetProjectNoticeFileDto> files = BeanUtil.copyToList(req.getFiles(), BudgetProjectNoticeFileDto.class);
        int result = budgetProjectNoticeService.modifyBudgetProjectNotice(dto, files);
        return ResponseDto.getSuccessResponseDto(result);
    }

}
